package dyyx;

import groovy.lang.Binding;
import groovy.lang.GroovyShell;

// jdk8 -XX:MaxMetaspaceSize=50m
public class MetaSpaceOom2 {
	
	// 不会 oom 
	// jcmd 49829 PerfCounter.print
	// java.cls.loadedClasses=89716
	// java.cls.unloadedClasses=81789

	public static void main(String[] args) throws Exception {
		System.out.println("MetaSpaceOom");
		int num = 10000000;
		for (int i = 0; i < num; i++) {
			// 表达式不一样才会生成新的class
			String expression = "1+" + i;
			Binding context = new Binding();
			GroovyShell shell = new GroovyShell(context);
			Object result = shell.evaluate(expression);
			System.out.println(result);
		}
	}
}
